'use strict';
var clientWidgets = angular.module('clientWidgets');
var clientApp = angular.module('clientApp');

//clientWidgets.controller('listThumbCtrl', function ($scope, $rootScope) {
//    $scope.myTree = [];
//    $scope.myAlert = function () {
//        alert('1');
//    };
//});

clientApp.directive('gridWidget', ['$rootScope', 'Constant', 'Util', 'DomUtil', 'WidgetUtil',
    function($rootScope, Constant, Util, DomUtil, WidgetUtil) {

    DomUtil.loadComponent('themes/flat/widget/list/grid/style/style.css', null);
    return {
        templateUrl: 'themes/flat/widget/list/grid/view/main.html',
        replace: true,
        transclude: true,
        restrict: 'E',
        scope: {
            itemsData: '=itemsModel',
            propMap: '=propModel'
            //method: '&'
        },
        link: function(scope, element, attrs) {
            scope.$watch('itemsData', function (newVal, oldVal) {
                if (newVal) {
                    scope.items = WidgetUtil.convert(scope.itemsData, scope.propMap);

                    var contentWidth = DomUtil.getColumnWidth($(element)[0].clientWidth, 10)
                    $('.io-56-wdg-grid li').css('width', contentWidth + 'px');
                    $('.io-56-wdg-grid li').css('height', contentWidth * 1.3 + 'px');

                    $('.io-56-wdg-grid li img, .io-56-wdg-grid li .item-descr').css('width', contentWidth + 'px');
                    $('.io-56-wdg-grid li img').css('height', contentWidth * 1.3 + 'px');

                    $(element).height(Util.getScreenSize().h - 120 + 'px');
                    setTimeout(function() {
                        var myScroll = new IScroll($(element)[0]);
                        $('.load-more').css('display', 'block');
                    }, 20);

                }
            });
        }
    };
}]);



